home *** CD-ROM | disk | FTP | other *** search
- /*
- *--- PageMakerMemory.c --------------------------------------------------------
- * Copyright (C) 1988-95 Adobe Systems, Inc. All rights reserved.
- *
- * This file contains the PageMaker memory manager interface for both the
- * Mac OS and Windows 95 environments. These are wrapper functions that
- * you can use in your PageMaker plug-in source code.
- *
- * Multiple Locks -
- * Locks do not stack. Locking the same block more than one time yields
- * results that are not consistent across all environments. Don't do
- * it. Under Windows, a block that is locked twice then unlocked once
- * is still locked -- on the Mac it is left unlocked.
- *------------------------------------------------------------------------------
- */
-
- #include <stdlib.h> // For calloc() & free() prototypes
- #ifdef MACINTOSH
- #include <Memory.h>
- #endif //MACINTOSH
- #ifdef WINDOWS
- #include <Windows.h> // Windows header file provides it's own double include protection
- #endif //MACINTOSH
-
- #include "PMMemory.h"
-
- /*
- *--- MMAlloc ------------------------------------------------------------------
- * Allocate a block from the global heap. The new block is relocatable
- * (must be locked before it can be used) and non-purgable. Handles to
- * blocks are valid only to the application that allocated them and cannot
- * be passed from one application to another.
- * Depending on the environment, the actual number of bytes allocated may
- * be slightly larger than the requested.
- *
- * SIDE EFFECTS:
- * Memory is allocated from the global heap. It should later be freed with
- * a call to MMFree().
- *------------------------------------------------------------------------------
- */
- PMHandle MMAlloc(size_t sz)
- {
- #if WINDOWS
- return (PMHandle) GlobalAlloc(GMEM_MOVEABLE, (unsigned long) sz);
- #else
- return NewHandleClear(sz);
- #endif
- }
-
-
- /*
- *--- MMFree -------------------------------------------------------------------
- * Free a block allocated by MMAlloc().
- *------------------------------------------------------------------------------
- */
- void MMFree(PMHandle h)
- {
- #if WINDOWS
- GlobalFree(h);
- #else
- DisposHandle(h);
- #endif
- }
- /*
- *--- MMLock -------------------------------------------------------------------
- * Lock the memory block referenced by a handle. The handle must
- * have been allocated by MMAlloc().
- * Memory should later be unlocked with MMUnlock().
- *------------------------------------------------------------------------------
- */
-
- void * MMLock(PMHandle h)
- {
- #if WINDOWS
- // GlobalLock will fail if the block was purged.
- return (void *) GlobalLock(h);
- #else
- HLockHi(h);
- return (void *)(*h);
- #endif
- }
-
- /*
- *--- MMUnlock -----------------------------------------------------------------
- * Unlock a block of memory that was locked by MMUnlock().
- * The block of memory in the global heap is made moveable.
- *------------------------------------------------------------------------------
- */
- void MMUnlock(PMHandle h)
- {
- #if WINDOWS
- GlobalUnlock(h);
- #else
- HUnlock(h);
- #endif
- }
-
- /*
- *--- MMIsLocked ---------------------------------------------------------------
- * Determine whether the memory referenced by the handle is locked
- * or unlocked. The handle must be be a legal handle (not NULL,
- * not garbage). Errors are not reported, but always result in a
- * return of false.
- *------------------------------------------------------------------------------
- */
- PMBool MMIsLocked(PMHandle h)
- {
- #if WINDOWS
- return ((GlobalFlags(h) & GMEM_LOCKCOUNT) > 0) ? true : false;
- #else
- char ch = HGetState(h);
- return (ch & 0x80 ? true : false);
- #endif
- }
-
- /*
- *--- MMResizeHandle -----------------------------------------------------------
- * Changes size of an unlocked memory block to new specified size.
- *------------------------------------------------------------------------------
- */
- PMErr MMResizeHandle(PMHandle * h, size_t sz)
- {
- #if WINDOWS
- return (PMErr) GlobalReAlloc(h, sz, GMEM_MOVEABLE);
- #else
- SetHandleSize(*h, sz);
- return -MemError();
- #endif
- }
-
- // end of PageMakerMemory.c
-